﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TARLib.Operazioni
{
    public class Operazione_Incassa : Operazione
    {
        // 006[0/1-gratis]
        public Operazione_Incassa(string barcodeString)
            : base(barcodeString)
        {
            if (barcodeString.Length == 4)
            {
                if (barcodeString.Substring(0, 3) == "006")
                {
                    if (barcodeString.Substring(3, 1) == "0")
                    {
                        Gratis = false;
                    }
                    else if (barcodeString.Substring(3, 1) == "1")
                    {
                        Gratis = true;
                    }
                    else
                    {
                        throw new Exception("Barcode 4th char (" + barcodeString.Substring(3, 1) + ") is invalid. Expected: 0 or 1");
                    }
                }
                else
                {
                    throw new Exception("Barcode first 3 chars (" + barcodeString.Substring(0, 3) + ") are invalid. Expected: 006");
                }
            }
            else
            {
                throw new Exception("Barcode lenght (" + barcodeString + ") is invalid. Expected: 4");
            }
        }

        public Operazione_Incassa()
            : base()
        {
        }

        public bool Gratis { get; set; }
        public override TipoOperazione Tipo { get { return TipoOperazione.Incassa; } }
        public override string BarcodeString { get { return String.Format("006{0}", Gratis == true ? "1" : "0"); } }
    }
}
